<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://unpkg.com/vue/dist/vue.js"></script>
  <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
  <style>
    .active {
      color: red;
    }
  </style>
</head>

<body>
  <div id="app">
    <ul>
      <router-link active-class="active" tag="li" to="/position/2/city/22">前端开发</router-link>
      <router-link active-class="active" tag="li" to="/position/1/city/11">后端开发</router-link>
      <router-link active-class="active" tag="li" to="/search">搜索</router-link>
      <router-link active-class="active" tag="li" to="/my">我的</router-link>
      <router-link active-class="active" tag="li" to="/product">产品展示</router-link>

      <router-link :to="{name:'p',params:{id:100,cityid:50}}">大数据</router-link>
    </ul>
    <div>
      <router-view></router-view>
    </div>

    <button @click="handleClick">去往前端开发的页面</button>

  </div>

  <script>


    var routes = [
      {
        path: "/position/:id/city/:cityid", 
        name:'p',
        component: {
          template: `<div>职位信息:{{$route.params.id}}-{{$route.params.cityid}}</div>`,
          watch: {
            $route(to, from) {
              console.log(to, from)
            }
          }
        }
      },
      {
        path: "/search", 
        name:'s',
        component: { template: `<div>搜索</div>` }
      },
      {
        path: "/my", component: { template: `<div>我的</div>` }
      },{
        path:'*',
        component:{
          template:`<h1>页面未找到</h1>`
        }
      }
    ]


    var router = new VueRouter({
      routes
    })


    var vm = new Vue({
      router,
      methods:{
        handleClick(){
          // this.$router.push('/position/5/city/10')
          // this.$router.push({path:'/position/5/city/10'})
          router.push({name:'s'})
        }
      }
    }).$mount('#app')

  </script>

</body>

</html>